﻿using System;
using System.Configuration;
namespace IgoCMS.Web
{
    public sealed class ConfigHelper
    {
        private static string xec6944b0446b972f = ConfigHelper.Get("AppPrefix");
        public static string Get(string key)
        {
            if (ConfigurationManager.AppSettings[key] == null)
            {
                return "";
            }
            return ConfigurationManager.AppSettings[key].ToString();
        }
        public static string GetConfigString(string key)
        {
            string name = ConfigHelper.xec6944b0446b972f + key;
            //object obj = DataCache.Get(name);
            //if (obj == null)
            //{
            //    try
            //    {
            //        obj = ConfigHelper.Get(key);
            //        if (obj != null)
            //        {
            //            DataCache.Set(name, obj, null, DateTime.Now.AddMinutes(180.0), TimeSpan.Zero);
            //        }
            //    }
            //    catch
            //    {
            //    }
            //}
            return "";
        }
        public static bool GetConfigBool(string key)
        {
            bool result = false;
            string configString = ConfigHelper.GetConfigString(key);
            if (configString != null && string.Empty != configString)
            {
                try
                {
                    result = bool.Parse(configString);
                }
                catch (FormatException)
                {
                }
            }
            return result;
        }
        public static decimal GetConfigDecimal(string key)
        {
            decimal result = 0m;
            string configString = ConfigHelper.GetConfigString(key);
            if (configString != null && string.Empty != configString)
            {
                try
                {
                    result = decimal.Parse(configString);
                }
                catch (FormatException)
                {
                }
            }
            return result;
        }
        public static int GetConfigInt(string key)
        {
            int result = 0;
            string configString = ConfigHelper.GetConfigString(key);
            if (configString != null && string.Empty != configString)
            {
                try
                {
                    result = int.Parse(configString);
                }
                catch (FormatException)
                {
                }
            }
            return result;
        }
    }
}
